import axios from 'axios'

const service = axios.create({
   baseURL: 'http://192.168.124.7',
   timeout: 5000,
    headers:{
        'Content-Type': 'application/json; charset=UTF-8'
    },
});

service.interceptors.request.use(config => {
    const token = sessionStorage.getItem('token')?JSON.parse(sessionStorage.getItem('token')):null;
    if(token) {
        config.headers = {
            'token': token
        };
    }
    return config
},error => {
    console.log(error); // for debug
    return Promise.reject(error);
});

service.interceptors.response.use(response => {
    const res = response.data;
    return response;
}, error => {
    console.log('err:' + error); // for debug
    return Promise.reject(error);
});

export default service